package com.cn.lyl.servlet.service;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.ServiceModel;
import com.cn.lyl.service.ServiceService;
import com.cn.lyl.service.impl.ServiceServiceImpl;
import com.cn.lyl.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/service/add")
public class AddServiceServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String serviceName = req.getParameter("serviceName");
        Float marketPrice = Tool.stringToFloat(req.getParameter("marketPrice"));
        Float price = Tool.stringToFloat(req.getParameter("price"));
        String intro = req.getParameter("intro");
        String flow= req.getParameter("flow");
        String face= req.getParameter("head_pic");
        String type = (req.getParameter("type"));
        System.out.println(type);
        ServiceModel serviceModel = new ServiceModel();
        serviceModel.setServiceName(serviceName);
        serviceModel.setMarketPrice(marketPrice);
        serviceModel.setPrice(price);
        serviceModel.setIntro(intro);
        serviceModel.setFlow(flow);
        serviceModel.setFace(face);
        serviceModel.setDependenceObj(type);

        ServiceService newsService =new ServiceServiceImpl();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",newsService.addService(serviceModel));
        resp.getWriter().print(jsonObject);
    }
}
